package cn.kbblog.activemq;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class TopicReceiver1  implements MessageListener{
	private static final Logger  LOGGER = LoggerFactory.getLogger(TopicReceiver1.class);
//	public static int num = 200;
	
	@Override
	public void onMessage(Message arg0) {
		try {
            String msg = "TopicReceiver1接收到消息:"+ ((TextMessage)arg0).getText();
			System.out.println(msg);
//			//模拟并发
//			if(TopicReceiver1.num > 0){
//				try {
//					Thread.sleep(300);//耗时操作
//				} catch (InterruptedException e) {
//					e.printStackTrace();
//				}
//				TopicReceiver1.num --;
//			}
//			System.out.println("num:"+ TopicReceiver1.num);
			
			
            LOGGER.info (msg);
        } catch (JMSException e) {
            LOGGER.error("error {}", e);
        }
	}

}
